/**
 *	@project:	kybernetes
 *	@author:	D.Toepel
 *	@note:		---
 *	
 *	Copyright (C) 2009  D.Toepel <de.dtools> {at} <gmail> {dot} <com>
 *	
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 */
package dt.htwk.panels;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import dt.htwk.core.KCStatusBar;
import dt.htwk.res.Resource;
import dt.htwk.rmi.BroadCastClient;
import dt.htwk.rmi.BroadCastServer;
import dt.htwk.rmi.RMIClient;
import dt.htwk.rmi.RMIServer;

/**
 * <h3>CommonSettings</h3>
 *
 * @author DToepel
 *
 */
public class CommonSettings extends JPanel {
	
/* ****************************************************
 * Deklaration der Variablen und Komponenten
 * ***************************************************/

	/**
	 * serialVersionUID -- Standard: 1L
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 
	 */
	private static Hashtable<String, String> lng;

	private RMIServer rmis;
	

/* ****************************************************
 * Aufruf des Konstruktors
 * ***************************************************/

	/**
	 * @param lng
	 */
	public CommonSettings(Hashtable<String, String> lng) {
		CommonSettings.lng = lng;
		initGUI();
	}

	
/* ****************************************************
 * PUBLIC - oeffentliche Methoden
 * ***************************************************/

	

/* ****************************************************
 * PRIVATE - nicht-oeffentliche Methoden
 * ***************************************************/

	private void initGUI(){
		this.add(new JLabel("CommonSettings - in Arbeit   ||   "));
		{
			this.add(new JLabel("Statusleiste testen:   ")); 
			JButton btn;
			btn = new JButton(Resource.connectIcon);
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					KCStatusBar.setConnected();
				}
			});
			this.add(btn);
			btn = new JButton(Resource.disconnectAIcon);
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					KCStatusBar.setDisconnectedA();
				}
			});
			this.add(btn);
			btn = new JButton(Resource.disconnectBIcon);
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					KCStatusBar.setDisconnectedB();
				}
			});
			this.add(btn);
			final JTextField tf = new JTextField();
			tf.setPreferredSize(new Dimension(120,27));
			this.add(tf);
			btn = new JButton("Statustext");
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					KCStatusBar.setStatusMessage(tf.getText());
				}
			});
			this.add(btn);
			btn = new JButton("BC Server");
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					BroadCastServer bcs = new BroadCastServer();
					bcs.start();
				}
			});
			this.add(btn);
			btn = new JButton("Start RMI Server");
			try {
				if(rmis==null)rmis = new RMIServer();
			} catch (RemoteException e) {
			}
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					setServer();
					
//					RMIServer.setTestText("isRunning: " + RMIServer.isRunning());;
				}
			});
			this.add(btn);
			btn = new JButton("BC Client");
			btn.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					BroadCastClient bcc = new BroadCastClient();
					bcc.start();
				}
			});
			this.add(btn);
		}

	}
	private void setServer(){
		if (rmis.isRunning()){
			System.out.println(rmis.SrvStop());
		}else {
			System.out.println(rmis.SrvStart());
		}
		System.out.println(rmis.getSrvdir());
	}

}
